﻿using Gzh.BLL.Infrastructure;
using Gzh.Core.Constant;
using Gzh.DAL.DAO;
using Gzh.DAL.Models;
using Gzh.DAL.Transaction;
using Gzh.Lib;
using Gzh.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Gzh.BLL.Service
{
    /// <summary>
    /// ${table.comment}
    /// </summary> 
    public class ${ClassName}Service : ${ClassName}DAO, I${ClassName}Contract
    {

        public TUserBaseInfoDAO TUserBaseInfoDAO { get; set; }
        public TSysUserDAO TSysUserDao { get; set; }

        //添加
        public OperationResult AddInfo(${TableName} data)
        {
            var operatorId = data.create_user_id.Value;
            var user = TSysUserDao.GetById(operatorId);
            if (user == null)
            {
                return new OperationResult("操作人不存在不存在");
            }
            //其它判断

            return base.Add(data);
        }


        //---------------------------------------------------------------------------------------------------------------------------------------------       

        //修改
        public OperationResult UpdateInfo(${TableName} data)
        {
            var temp = base.GetById(data.id);
            if (temp == null)
            {
                return new OperationResult("修改的记录不存在");
            }

            //其它判断

            return base.Update(x => new
            {
                 <#list table.columns  as column>
                  <#if column_has_next>
                   x.${column.columnName},    //${column.columnComment}
                   <#else>
                   x.${column.columnName}    //${column.columnComment}
                  </#if>
                 </#list>
            }, data);

        }

        //---------------------------------------------------------------------------------------------------------------------------------------------       

        //删除
        public OperationResult DeleteById(long id, long operatorId)
        {
            var temp = base.GetById(id);
            if (temp == null)
            {
                return new OperationResult("记录已经删除");
            }

            var user = TUserBaseInfoDAO.GetByUserId(operatorId);
            if (user == null)
            {
                return new OperationResult("操作者id不存在");
            }

            return base.Delete(id);


        }
        //---------------------------------------------------------------------------------------------------------------------------------------------  

    }
}
